<!-- 撤销领用 -->
<template>
  <view class="">
    <!--    <view class="uni-page-head" v-if="titleFlag">-->
    <!--      <image class="common-title-img" style="left: 20rpx;"-->
    <!--             :src="require('../../static/imges/fanhui.png')" @click="back()"></image>-->
    <!--      <view class="uni-page-head-title">-->
    <!--        撤销领用-->
    <!--      </view>-->
    <!--    </view>-->
    <!--    <view v-if="titleFlag" style="margin-top: 90rpx;">-->
    <!--      &lt;!&ndash; 这个盒子是用来撑空间，又不想改变下边的body盒子 所以在这加了一个空盒子，可以根据新老MOA判断 &ndash;&gt;-->
    <!--    </view>-->
    <view style="width: 100%; margin-top: 20rpx;" v-for="(item,index) in baseList" :key="index">
      <view class="common-body-ex">
        <view class="list-title-son" style="text-align: right;">
          <text>物料名称</text>
          <text>出库数量</text>
        </view>
        <view class="common-list-ex-patch" style="display: flex;justify-content:space-around;">

          <text class="" style="height: auto; width: 20%;white-space: nowrap;overflow: hidden;text-overflow: ellipsis"
                type="text" :selectable="true">{{ item.categoryName }}
          </text>
          <text class="" style="width: 20%;height: auto;text-align: center;padding-right: 15px;" type="text">
            {{ item.osAmount }}
          </text>

        </view>
        <view class="common-list-ex-patch" v-if="type==='2'">

          <label class="common-list-title-ex">站址编码 :</label>

          <text class="common-list-text-ex-patch" style="height: auto;" type="text" :selectable="true">
            {{ item.siteId }}
          </text>

        </view>
        <view class="common-list-ex-patch">

          <label class="common-list-title-ex">申领明细ID :</label>

          <text class="common-list-text-ex-patch" style="height: auto;" type="text" :selectable="true">
            {{ item.applySno }}
          </text>

        </view>

        <view class="common-list-ex-patch">

          <label class="common-list-title-ex">物料编码 :</label>

          <text class="common-list-text-ex-patch" style="height: auto;" type="text" :selectable="true">
            {{ item.categoryCode }}
          </text>

        </view>
        <view class="common-list-ex-patch" style="height: auto">

          <label class="common-list-title-ex">物料名称 :</label>

          <text class="common-list-text-ex-patch" style="height: auto;" type="text" :selectable="true">
            {{ item.categoryName }}
          </text>

        </view>
        <view class="common-list-ex-patch">

          <label class="common-list-title-ex">规格 :</label>

          <text class="common-list-text-ex-order" style="height: auto;" type="text" :selectable="true">
            {{ item.formPattern }}
          </text>

        </view>


        <view class="common-list-ex-patch">

          <label class="common-list-title-ex">单位计量 :</label>


          <text class="common-list-text-ex-patch" style="height: auto;" type="text">{{ item.dwjl }}</text>
        </view>
        <view class="common-list-ex-patch">

          <label class="common-list-title-ex">计量单位 :</label>


          <text class="common-list-text-ex-patch" style="height: auto;" type="text">{{ item.unit }}</text>
        </view>

        <view class="common-list-ex-patch">

          <label class="common-list-title-ex">申领数量 :</label>


          <text class="common-list-text-ex-patch" style="height: auto;" type="text">{{ item.amount }}</text>
        </view>
        <view class="common-list-ex-patch">

          <label class="common-list-title-ex">累计撤销数量 :</label>


          <text class="common-list-text-ex-patch" style="height: auto;" type="text">{{ item.backAmount }}</text>
        </view>
        <view class="common-list-ex-patch">

          <label class="common-list-title-ex">未同步仓储撤销数量 :</label>

          <text class="common-list-text-ex-patch" style="height: auto;" type="text">{{ item.backingAmount }}</text>
        </view>
        <view class="common-list-ex-patch">

          <label class="common-list-title-ex">累计出库数量 :</label>


          <text class="common-list-text-ex-patch" style="height: auto;" type="text">{{ item.osAmount }}</text>
        </view>
        <view class="common-list-ex-patch">

          <label class="common-list-title-ex">累计退库数量 :</label>


          <text class="common-list-text-ex-patch" style="height: auto;" type="text">{{ item.retreatAmount }}</text>
        </view>
        <view class="common-list-ex-patch">

          <label class="common-list-title-ex">待出库数量 :</label>


          <text class="common-list-text-ex-patch" style="height: auto;" type="text">{{ item.noReceiveAmount }}</text>
        </view>
        <view class="common-list-ex-patch2" style="background-color: white;">

          <label class="common-list-title-ex">
            <text style="color: red;">*</text>
            本次撤销领用数量 :</label>

          <input style="font-size: 28rpx;background-color:white;" @input="onInput" class="common-list-inpur-ex"
                 type="digit" v-model="receiveAmount" placeholder="请输入"/>

        </view>
      </view>

      <view class="common-btn-body">
        <button class="common-btn" type="warn" v-debounce="save" :disabled="disabledButton">提交</button>
        <button class="common-btn" @click="chongxiao()" style="border:1px solid #EB4B4B;color:#EB4B4B ;">取消</button>
      </view>


    </view>


  </view>
</template>

<script>
import talkingdata from '../../common/talkingdata.js';

export default {
  data() {
    return {
      baseList: [],
      prjId: '',
      type: '',
      receiveAmount: '',
      disabledButton: true,
    }
  },
  onLoad(option) {
    this.prjId = option.prjId
    this.type = option.type
    this.baseList.push(JSON.parse(decodeURIComponent(option.item)));
  },
  onReady() {
    console.log("执行onReady")
    //在页面挂载完成后，调用外部埋点，统计数据
    const script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = talkingdata.talkingKey;
    document.body.appendChild(script);

  },
  methods: {
    back() {
      uni.navigateBack({
        delta: 1
      });
    },
    jump() {
      console.log("出发")
      uni.navigateTo({
        url: '../work_detail/test'
      });
    },
    chongxiao() {
      this.receiveAmount = "";
      uni.navigateBack({
      	delta: 1
      })
    },

    save() {
      let that = this
      if (that.receiveAmount == "") {
        return;
      }


      uni.showModal({
        title: '温馨提示',
        content: "是否确认提交",
        confirmColor:'#eb4b4b',

        success: function (res) {
          if (res.confirm) {
            //精度校验
            let paramsCode = {
              materialCode: that.baseList[0].categoryCode,
              receiveAmount: that.receiveAmount,
              amountType: '2',
              siteId: that.baseList[0].siteId,
            }
            that.$axios.post("/material/api/receive/equip/getSpuUnitAccByMaterialCode", paramsCode).then(() => {
              const params = {
                ...that.baseList[0],
                receiveAmount: that.receiveAmount,
              }
              that.$axios.post("/material/api/receive/equip/doSaveBackInfo", params).then((result) => {
                uni.showModal({
                  title: '温馨提示',
                  content: result.message,
                  confirmColor:'#eb4b4b',
                  showCancel: false,
                  success: function (res1) {
                    if (res1.confirm) {
                      //该方法用于刷新父页面
                      uni.navigateBack({
                        delta: 1
                      })

                    }
                  }
                })
              })
            })
          }
        }
      });

    },
    onInput(event) {
      if (event.detail.value !== '') {
        this.disabledButton = false
      } else {
        this.disabledButton = true
      }
    }
  }
}
</script>


<style>
@import '@/common/common-ui.css';
</style>
